package club.dmyang.service;

import club.dmyang.dao.FriendShipLinkMapper;
import club.dmyang.entity.FriendShipLink;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by brss on 2018/8/14.
 */
@Service("friendshipLinkService")
public class FriendshipLinkServiceImpl implements FriendshipLinkService {

    @Autowired
    private FriendShipLinkMapper friendShipLinkMapper;


    /**
     * 添加一条友情连接
     *
     * @param friendShipLink
     * @return
     */
    @Override
    public boolean addOneFriendshipLink(FriendShipLink friendShipLink) {
        try {
            friendShipLinkMapper.insertSelective(friendShipLink);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    /**
     * 由主键删除一条友链
     *
     * @param flid
     * @return
     */
    @Override
    public boolean delOneFriendshipLink(Integer flid) {
        int i = friendShipLinkMapper.deleteByPrimaryKey(flid);
        if (i>0)
            return true;
        return false;
    }

    /**
     * 考虑友链个数不会太多，不分页
     *
     * @return
     */
    @Override
    public List<FriendShipLink> findAllFriendshipLink() {
        return friendShipLinkMapper.selectAll();
    }

    /**
     * 由注解查询一条友链
     *
     * @param flid
     * @return
     */
    @Override
    public FriendShipLink findOneFriendshipLink(Integer flid) {
        return friendShipLinkMapper.selectByPrimaryKey(flid);
    }

    /**
     * 修改一条友链
     *
     * @param friendShipLink
     * @return
     */
    @Override
    public boolean changeOneFriendshipLink(FriendShipLink friendShipLink) {
        int i = friendShipLinkMapper.updateByPrimaryKeySelective(friendShipLink);
        if (i>0)
            return true;
        return false;
    }
}
